#include <gtest/gtest.h>
#include <iostream>

// 这里继承的environment环境类，在任何TEST中都会被调用
// class MyEnvironment : public testing::Environment
// {
// public:
//     virtual void SetUp() override
//     {
//         std::cout << "初始化测试环境\n";
//     }
//     virtual void TearDown() override
//     {
//         std::cout << "测试环境清理\n";
//     }
// };

// TEST(a, less_test)
// {
//     int age = 20;
//     EXPECT_LT(age, 20);
//     printf("OK!\n");
// }
// TEST(a, great_test)
// {
//     int age = 20;
//     EXPECT_GT(age, 18);
//     printf("OK!\n");
// }

// 证明了SetUp和TearDown会对每一个test均起作用
std::unordered_map<std::string, std::string> mymap;
class MyMapTest : public testing::Environment
{
public:
    virtual void SetUp() override
    {
        std::cout << "单元测试执行前的环境初始化！！\n";
        mymap.insert(std::make_pair("hello", "你好"));
        mymap.insert(std::make_pair("bye", "再见"));
    }
    virtual void TearDown() override
    {
        std::cout << "单元测试执行完毕后的环境清理！！\n";
        mymap.clear();
    }
};
TEST(b, test1)
{
    ASSERT_EQ(mymap.size(), 2);
    mymap.erase("hello");  
}

TEST(b, test2)
{
    ASSERT_EQ(mymap.size(), 2);
}

int main(int argc, char *argv[])
{
    testing::InitGoogleTest(&argc, argv);
    // testing::AddGlobalTestEnvironment(new MyEnvironment);
    testing::AddGlobalTestEnvironment(new MyMapTest);
    return RUN_ALL_TESTS();
}